#!/bin/bash

CFLAGS=-g -W 
EFLAGS=-O3 -o
LIBS=-lX11 -lglut -lGL -lGLU -lfreetype -lm -lMagick++
INCLUDE = -I/usr/include/freetype2
CXX=g++
EXECUTS=atlantis

SOURCES=$(wildcard *.cpp)
OBJECTS:= $(SOURCES:.cpp=.o)
OBJDIR = ./bin/

ARCH:=$(shell uname -m)
BIT32:=i686
BIT64:=x86_64

ifeq ($(ARCH), $(BIT32))
	CFLAGS=-g -W -m32
	EFLAGS = -O3 -m32 -o
else
	CFLAGS=-g -W -m64
	EFLAGS = -O3 -m64 -o
endif


#判断编译模式
ifdef DEBUG
	MODE = debug
	MODEFLAG = -g -D_DEBUG
else
	MODE = release
	MODEFLAG = -O3 -DNDEBUG
endif

#根据shell命令uname得到当前操作系统的名字字符串，用于判断不同操作系统
OSNAME = $(shell uname)
ifeq ($(OSNAME), Linux)
	CXX = g++
endif


$(EXECUTS):$(OBJECTS)
	$(CXX) $(EFLAGS) $@ $(OBJECTS) $(CFLAGS) $(LIBS) $(INCLUDE)

%.d : %.cpp
	$(CXX) -MM $(CFLAGS) $(LIBS) $< -o $@

%.o : %.cpp
	$(CXX) $(CFLAGS)  $(INCLUDE) $(LIBS) $< -c 

.PHONY : all clean

all: $(EXECUTS)

dep:$(SOURCES)
	@$(CXX) -MM $(SRCS) > $@

dirs:
	if [ -d $(OBJDIR) ]; then true; else mkdir -p $(OBJDIR); fi; \

clean : 
	rm -rf $(EXECUTS) $(OBJECTS) 
	rm -rf ${OBJECTS:.o=.d}

include ${OBJECTS:.o=.d}
